from django.conf import settings
from cryptography.fernet import Fernet

def encrypt(text):
  f = Fernet(settings.SSO_SECRET)
  token = f.encrypt(bytes(text, encoding='utf8'))
  print(token)
  return token

def decrypt(token):
  try:
    f = Fernet(settings.SSO_SECRET)
    text = f.decrypt(bytes(token, encoding='utf8'))
    return text.decode("utf-8")
  except Exception as e:
    print(str(e))
    return None